Skip to content

Conversation

@psainics
Copy link
Contributor

@psainics psainics commented Nov 20, 2024

ErrorDetailsProvider - MySql [Source|Sink] plugin

Jira : PLUGIN-1824

Description

Implement Program Failure Exception Handling in MySql Source/Sink plugin to catch known errors

Code change

  • Added DBErrorDetailsProvider.java
  • Added MysqlErrorDetailsProvider.java
  • Modified DBRecord.java
  • Modified AbstractDBSink.java
  • Modified AbstractDBSource.java
  • Modified MysqlConstants.java
  • Modified MysqlSink.java
  • Modified MysqlSource.java
  • Modified MysqlUtil.java

@psainics psainics changed the title Add MysqlErrorDetailsProvider [PLUGIN-0000] ErrorDetailsProvider - MySql Source/Sink plugin Nov 20, 2024
@psainics psainics changed the title [PLUGIN-0000] ErrorDetailsProvider - MySql Source/Sink plugin [PLUGIN-1824] ErrorDetailsProvider - MySql Source/Sink plugin Nov 20, 2024
@psainics psainics marked this pull request as ready for review November 20, 2024 11:57
@psainics psainics self-assigned this Nov 20, 2024
@psainics psainics marked this pull request as draft November 20, 2024 11:58
@psainics psainics added the build label Nov 20, 2024
if (sourceConfig.canConnect()) {
try {
stageConfigurer.setOutputSchema(getSchema(driverClass));
stageConfigurer.setOutputSchema(getSchema(driverClass, collector));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are already adding the exception in failure collector below by catching it, why is this extra step needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can you please add sql state and error code in the message on line 127?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added SQL error details.

@psainics psainics force-pushed the fem/mysql branch 2 times, most recently from b755515 to 84432d6 Compare November 21, 2024 09:03
@psainics psainics marked this pull request as ready for review November 22, 2024 08:59
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
errorMessage,
String.format(errorMessageFormat, errorContext.getPhase(), errorMessage), ErrorType.SYSTEM, false, e);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed !

Copy link
Contributor

@itsankit-google itsankit-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add open and capture logs step in the e2e tests where pipeline also fails so that we can verify the expected logs?

for example:

Scenario: Verify that pipeline fails when user provides invalid Credentials for connection with Macros

if (t instanceof IllegalStateException) {
return getProgramFailureException((IllegalStateException) t, errorContext);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed !

*
* @return The external documentation link as a {@link String}.
*/
protected String getExternalDocumentationLink() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this method used in this class?

Copy link
Contributor

@itsankit-google itsankit-google Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ! This makes sense, I though this will be called by the platform and display on UI.

I have added the doc link in error details now !

Comment on lines 33 to 45
protected ErrorType getErrorTypeFromErrorCode(int errorCode) {
// https://dev.mysql.com/doc/refman/9.0/en/error-message-elements.html#error-code-ranges
if (errorCode >= 1000 && errorCode <= 1999 || errorCode >= 2000 && errorCode <= 2999 ||
errorCode >= 3000 && errorCode <= 4999 || errorCode >= 5000 && errorCode <= 5999) {
return ErrorType.USER;
} else if (errorCode >= 10000 && errorCode <= 49999 || errorCode >= 50000 && errorCode <= 51999) {
return ErrorType.SYSTEM;
} else {
return ErrorType.UNKNOWN;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be made more readable, something like this:

protected ErrorType getErrorTypeFromErrorCode(int errorCode) {
    // https://dev.mysql.com/doc/refman/9.0/en/error-message-elements.html#error-code-ranges
    // USER errors: General errors, server-specific, storage engine, and third-party engine errors
    if (errorCode >= 1000 && errorCode <= 5999) {
        return ErrorType.USER;
    }
    // SYSTEM errors: Enterprise and user-defined custom error messages
    else if (errorCode >= 10000 && errorCode <= 51999) {
        return ErrorType.SYSTEM;
    }
    // UNKNOWN errors: Anything outside defined ranges
    else {
        return ErrorType.UNKNOWN;
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated !

And Run the Pipeline in Runtime with runtime arguments
Then Wait till pipeline is in running state
Then Open and capture logs
And Open and capture logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this step looks duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed dupe !

addOutputContext(context);

// set error details provider
context.setErrorDetailsProvider(new ErrorDetailsProviderSpec(getErrorDetailsProviderClassName()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.setErrorDetailsProvider should be called before addOutputContext(context) is called.

Otherwise error details provider information is not propagated to platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, moved !

DataDrivenETLDBInputFormat.class, connectionConfigAccessor.getConfiguration())));

// set error details provider
context.setErrorDetailsProvider(new ErrorDetailsProviderSpec(getErrorDetailsProviderClassName()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly here:

context.setErrorDetailsProvider should be called before context.setInput(Input.of(sourceConfig.getReferenceName(), new SourceInputFormatProvider( DataDrivenETLDBInputFormat.class, connectionConfigAccessor.getConfiguration()))) is called.

Otherwise error details provider information is not propagated to platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved !

@itsankit-google
Copy link
Contributor

Please squash the commits before merge.

@psainics psainics merged commit 23af441 into data-integrations:develop Dec 9, 2024
10 checks passed
@psainics psainics deleted the fem/mysql branch December 9, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants